<?php
require "class.phpmailer.php" ;

class QQMail {
      private $SMTPServer;
      private $UserName;
      private $Password;
      private $From;

      function QQMail($smtp,$username,$password,$from) {
      	$this->SMTPServer = $smtp;
      	$this->UserName = $username;
      	$this->Password = $password;
      	$this->From = $from;
      }

   public function send($subject, $mailList, $body, $attachment="") {
      $mail = new PHPMailer();

      $mail->IsSMTP();                       // set mailer to use SMTP
      $mail->SMTPAuth = true;                // turn on SMTP authentication
      $mail->Host     = $this->SMTPServer;   // specify main and backup server
      $mail->Username = $this->UserName;     // SMTP username
      $mail->Password = $this->Password;     // SMTP password
      $mail->From     = $this->From;
      $mail->FromName = iconv('utf-8','gbk',"淘宝天猫");

      $mail->IsHTML(true);                   // set email format to HTML
      $mail->CharSet  = "GBK";            // set mail charset
      $mail->WordWrap = 80;                  // set word wrap to 80 characters

      $mail->Subject  = $subject;            // mail subject
      foreach($mailList as $k=>$v) {
         $mail->AddAddress($v);              // name is optional
      }
      if(!empty($body)) {
         $mail->Body  = $body;               // set mail body
      }
      if(!empty($attachment)) {
         $mail->AddAttachment($attachment);  // add attachments
      }
      
      $re = $mail->Send();

      if($re) {
         return 1;
      } else {
         return 0;
      }
   }
 }
?>
